package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ShopFriendlyLinks;
import com.ruoyi.system.service.IShopFriendlyLinksService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 友情连接Controller
 * 
 * @author ruoyi
 * @date 2024-06-11
 */
@RestController
@RequestMapping("/system/links")
public class ShopFriendlyLinksController extends BaseController
{
    @Autowired
    private IShopFriendlyLinksService shopFriendlyLinksService;

    /**
     * 查询友情连接列表
     */
    @PreAuthorize("@ss.hasPermi('system:links:list')")
    @GetMapping("/list")
    public TableDataInfo list(ShopFriendlyLinks shopFriendlyLinks)
    {
        startPage();
        List<ShopFriendlyLinks> list = shopFriendlyLinksService.selectShopFriendlyLinksList(shopFriendlyLinks);
        return getDataTable(list);
    }

    /**
     * 导出友情连接列表
     */
    @PreAuthorize("@ss.hasPermi('system:links:export')")
    @Log(title = "友情连接", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShopFriendlyLinks shopFriendlyLinks)
    {
        List<ShopFriendlyLinks> list = shopFriendlyLinksService.selectShopFriendlyLinksList(shopFriendlyLinks);
        ExcelUtil<ShopFriendlyLinks> util = new ExcelUtil<ShopFriendlyLinks>(ShopFriendlyLinks.class);
        util.exportExcel(response, list, "友情连接数据");
    }

    /**
     * 获取友情连接详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:links:query')")
    @GetMapping(value = "/{linkId}")
    public AjaxResult getInfo(@PathVariable("linkId") Long linkId)
    {
        return success(shopFriendlyLinksService.selectShopFriendlyLinksByLinkId(linkId));
    }

    /**
     * 新增友情连接
     */
    @PreAuthorize("@ss.hasPermi('system:links:add')")
    @Log(title = "友情连接", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShopFriendlyLinks shopFriendlyLinks)
    {
        return toAjax(shopFriendlyLinksService.insertShopFriendlyLinks(shopFriendlyLinks));
    }

    /**
     * 修改友情连接
     */
    @PreAuthorize("@ss.hasPermi('system:links:edit')")
    @Log(title = "友情连接", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShopFriendlyLinks shopFriendlyLinks)
    {
        return toAjax(shopFriendlyLinksService.updateShopFriendlyLinks(shopFriendlyLinks));
    }

    /**
     * 删除友情连接
     */
    @PreAuthorize("@ss.hasPermi('system:links:remove')")
    @Log(title = "友情连接", businessType = BusinessType.DELETE)
	@DeleteMapping("/{linkIds}")
    public AjaxResult remove(@PathVariable Long[] linkIds)
    {
        return toAjax(shopFriendlyLinksService.deleteShopFriendlyLinksByLinkIds(linkIds));
    }
}
